﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MO_Virtual_Router
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "Show")
            {
                pass.PasswordChar = '\0';
                button1.Text = "Hide";
            }
            else if (button1.Text == "Hide")
            {
                pass.PasswordChar = '*';
                button1.Text = "Show";
            }
            else
            {
                MessageBox.Show("We have a problem program will restart");
                Application.Restart();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (pass.TextLength > 7 || pass.TextLength < 62)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = "/C netsh wlan set hostednetwork mode=allow ssid=\"" + ssid.Text + "\" key=\"" + pass.Text + "\"";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.UseShellExecute = false;
                p.Start();
                string s = p.StandardOutput.ReadToEnd();
                MessageBox.Show(s + "\n Now you need to set your network adaptor. Give sharing to new Wi-Fi point \n After giving sharing start the Wi-Fi Point");
                p.WaitForExit();
                label3.Text = "Wi-Fi Point Created!";
            }
            else
                MessageBox.Show("Password length must be 8-63 char!!!");
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/C netsh wlan start hostednetwork";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false;
            p.Start();
            string s = p.StandardOutput.ReadToEnd();
            MessageBox.Show(s);
            p.WaitForExit();
            label3.Text = "Wi-Fi Started!";
           
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/C netsh wlan stop hostednetwork";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false;
            p.Start();
            string s = p.StandardOutput.ReadToEnd();
            MessageBox.Show(s);
            p.WaitForExit();
            label3.Text = "Wi-Fi Stopped!";
        }
    }
}
